home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / tkern10.zip / GNUISH\ERROR.C < prev    next >
C/C++ Source or Header  |  1990-09-19  |  3KB  |  110 lines

  1. /* error.c -- error handler for noninteractive utilities
  2.    Copyright (C) 1990 Free Software Foundation, Inc.
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 1, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /* David MacKenzie */
  19.  
  20. #include <stdio.h>
  21.  
  22. #ifndef VPRINTF_MISSING
  23.  
  24. #ifdef __STDC__
  25. #include <stdarg.h>
  26. #else
  27. #include <varargs.h>
  28. #endif
  29.  
  30. #else
  31.  
  32. #ifndef DOPRNT_MISSING
  33. #define va_alist args
  34. #define va_dcl int args;
  35. #else
  36. #define va_alist a1, a2, a3, a4, a5, a6, a7, a8
  37. #define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
  38. #endif
  39.  
  40. #endif
  41.  
  42. #ifdef STDC_HEADERS
  43. #include <stdlib.h>
  44. #include <string.h>
  45. #else
  46. void exit ();
  47.  
  48. #ifdef MSDOS
  49. /* Force consistency of the prototypes.  */
  50. #include <gnulib.h>
  51. #endif
  52.  
  53. static char *
  54. strerror (errnum)
  55.      int errnum;
  56. {
  57.   extern char *sys_errlist[];
  58.   extern int sys_nerr;
  59.  
  60.   if (errnum > 0 && errnum < sys_nerr)
  61.     return sys_errlist[errnum];
  62.   return "Unknown system error";
  63. }
  64. #endif
  65.  
  66. /* Print the program name and error message MESSAGE, which is a printf-style
  67.    format string with optional args.
  68.    If ERRNUM is nonzero, print its corresponding system error message.
  69.    Exit with status STATUS if it is nonzero. */
  70. /* VARARGS */
  71. void
  72. #if !defined (VPRINTF_MISSING) && defined (__STDC__)
  73. error (int status, int errnum, char *message, ...)
  74. #else
  75. error (status, errnum, message, va_alist)
  76.      int status;
  77.      int errnum;
  78.      char *message;
  79.      va_dcl
  80. #endif
  81. {
  82.   extern char *program_name;
  83. #ifndef VPRINTF_MISSING
  84.   va_list args;
  85. #endif
  86.  
  87.   fprintf (stderr, "%s: ", program_name);
  88. #ifndef VPRINTF_MISSING
  89. #ifdef __STDC__
  90.   va_start (args, message);
  91. #else
  92.   va_start (args);
  93. #endif
  94.   vfprintf (stderr, message, args);
  95.   va_end (args);
  96. #else
  97. #ifndef DOPRNT_MISSING
  98.   _doprnt (message, &args, stderr);
  99. #else
  100.   fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
  101. #endif
  102. #endif
  103.   if (errnum)
  104.     fprintf (stderr, ": %s", strerror (errnum));
  105.   putc ('\n', stderr);
  106.   fflush (stderr);
  107.   if (status)
  108.     exit (status);
  109. }
  110.